
#include "process_fork.h"

void fork_exec()
{
    int pid = fork();
    switch (pid)
    {
        case -1:
            printf("fork fail!\n");
            exit(1);
        case 0:
            execl("/bin/ls", "-l", "-color", NULL);
            printf("execl fail!\n");
            exit(1);
        case 1:
            wait(NULL);
            printf("ls completes!\n");
            exit(0);
        default:
            wait(NULL);
            printf("ls completes!\n");
            exit(0);
    }
}


void more_fork()
{
    int p1, p2;
    while ((p1 = fork()) == -1)
        ;
    if (p1 == 0)
    {
        putchar('b');
    }
    else
    {
        while ((p2 = fork()) == -1)
            ;
        if (p2 == 0)
        {
            putchar('c');
        }
        else
        {
            putchar('a');
        }
    }
}

